package day11.byteStream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author Xiao
 * @date 2021/8/1
 */
public class InputDemo02 {
    /**
     * 读取文件中多个字节数据：
     * 创建FileInputStream对象,关联文件
     * 通过循环读取文件,调用read()方法
     * 如果读取到的是-1,则停止循环
     * 调用close()方法释放资源
     */
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("E:\\develop\\IdeaProjects\\" +
                "JavaSE_Advance\\videoPractice\\src\\day11\\byteStream\\demo03.txt");
        int read;
        while ((read = fis.read()) != -1) {
            System.out.print((char) read);
        }
//        method(fis);
        fis.close();
    }



    private static void method(FileInputStream fis) throws IOException {
        while (true) {
            int read = fis.read();
            if (read == -1) {
                break;
            }
            System.out.print((char) read);
        }
    }
}
